package com.example.springboot_vue.controller;


import com.example.springboot_vue.common.CommonDto;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.Goodstype;
import com.example.springboot_vue.entity.StorageEntity;
import com.example.springboot_vue.service.GoodstypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sgp
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/goodstype")
public class GoodstypeController {

    @Autowired
    private GoodstypeService goodstypeService;

    @GetMapping("/selectAll")
    public CommonDto selectAll(Goodstype goodstype){
        CommonDto<PageDto<Goodstype>> commonDto = new CommonDto<>();
        PageDto<Goodstype> pageDto = goodstypeService.selectAll(goodstype);
        commonDto.setContent(pageDto);
        return commonDto;
    }

    @GetMapping("/del/{id}")
    public CommonDto del(@PathVariable Integer id){
        CommonDto<Goodstype> commonDto = new CommonDto<>();
        goodstypeService.removeById(id);
        commonDto.setMessage("删除成功");
        return commonDto;
    }

    @PostMapping("/save")
    public CommonDto save(@RequestBody Goodstype goodstype){
        CommonDto<StorageEntity> commonDto = new CommonDto<>();
        goodstypeService.save(goodstype);
        commonDto.setMessage("新增成功");
        return commonDto;
    }

    @PostMapping("/update")
    public CommonDto update(@RequestBody Goodstype goodstype){
        CommonDto<StorageEntity> commonDto = new CommonDto<>();
        goodstypeService.updateById(goodstype);
        commonDto.setMessage("修改成功");
        return commonDto;
    }

    @GetMapping("/list")
    public CommonDto list(){
        CommonDto<List<Goodstype>> commonDto = new CommonDto<>();
        List<Goodstype> list = goodstypeService.list();
        commonDto.setContent(list);
        return commonDto;
    }

}
